//
//  SNFCreditScoreCameraBaseView.m
//  SNCustomCamera
//
//  Created by User on 2018/8/29.
//  Copyright © 2018年 Raindew. All rights reserved.
//

#import "SNFCreditScoreCameraBaseView.h"
@interface SNFCreditScoreCameraBaseView ()

@property (nonatomic, strong)UIView *mView;//遮罩
@property (nonatomic, strong)UILabel *tipLabel;//提示语

@property (nonatomic, assign) CGFloat marginX;
@property (nonatomic, assign) CGFloat marginY;

@end

@implementation SNFCreditScoreCameraBaseView
 
#define kLineWidth 5
#define kLineLong 35
#define kLineColor [UIColor colorWithRed:41/255. green:130/255. blue:254/255. alpha:1.]

- (void)drawRect:(CGRect)rect {
    
    CGFloat width = 415;
    CGFloat height = 270;
    
    _marginX = (self.frame.size.width - width) / 2.0;
    _marginY = (self.frame.size.height - height) / 2.0;
    

    //绘制一个遮罩
    UIBezierPath *bpath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) cornerRadius:0];
     
    //贝塞尔曲线 画一个带有圆角的矩形
    [bpath appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(_marginX, _marginY, width, height) cornerRadius:0] bezierPathByReversingPath]];
    
   
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = bpath.CGPath;
    
    //添加图层蒙板
    self.mView.layer.mask = shapeLayer;
    
    UIColor *color = kLineColor;
    [color set]; //设置线条颜色
    UIBezierPath *path = [UIBezierPath bezierPath];
    
     
    //左上角
    [path moveToPoint:CGPointMake(_marginX + kLineWidth/2, _marginY + kLineLong + kLineWidth/2)]; // 下
    [path addLineToPoint:CGPointMake(_marginX + kLineWidth/2, _marginY + kLineWidth/2)]; // 左
    [path addLineToPoint:CGPointMake(_marginX + kLineLong + kLineWidth/2, _marginY + kLineWidth/2)]; // 右
    path.lineWidth = kLineWidth;
    
    //左下角
    [path moveToPoint:CGPointMake(_marginX + kLineWidth/2, CGRectGetHeight(self.frame) - _marginY - kLineLong)];
    [path addLineToPoint:CGPointMake(_marginX + kLineWidth/2, CGRectGetHeight(self.frame) - _marginY - kLineWidth/2)];
    [path addLineToPoint:CGPointMake(_marginX + kLineLong + kLineWidth/2, CGRectGetHeight(self.frame) - _marginY - kLineWidth/2)];
    path.lineWidth = kLineWidth;
    
    //右上角
    [path moveToPoint:CGPointMake(CGRectGetWidth(self.frame) - _marginX - kLineLong - kLineWidth/2, _marginY + kLineWidth/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - _marginX - kLineWidth/2, _marginY + kLineWidth/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - _marginX - kLineWidth/2, _marginY + kLineLong + kLineWidth/2)];
    path.lineWidth = kLineWidth;
    
    //右下角
    [path moveToPoint:CGPointMake(CGRectGetWidth(self.frame) - _marginX - kLineLong - kLineWidth/2, CGRectGetHeight(self.frame) - _marginY - kLineWidth/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - _marginX - kLineWidth/2, CGRectGetHeight(self.frame) - _marginY - kLineWidth/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - _marginX - kLineWidth/2, CGRectGetHeight(self.frame) - _marginY - kLineLong)];
    path.lineWidth = kLineWidth;
    
    [path stroke];
    
}


- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        //遮罩View
        self.mView = [[UIView alloc] initWithFrame:self.bounds];
        self.mView.backgroundColor = [UIColor blackColor];
        self.mView.alpha = 0.5;
        [self addSubview:self.mView];
    }
    
    return self;
}

 


@end
